package com.diguage.dytecode.dynamicproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 性能监控
 *
 * @author diguage
 * @since 2016-9-4.
 */
public class ProfilerInvocationHandler implements InvocationHandler {
    private Object realObject;
    public ProfilerInvocationHandler(Object realObject) {
        this.realObject = realObject;
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        long startTime = System.currentTimeMillis();
        String className = realObject.getClass().getName();
        Object result = method.invoke(realObject, args);
        System.out.println(className + "#" + method.getName() + " was invoked by " + (System.currentTimeMillis() - startTime) + " millisecond");
        return result;
    }
}
